﻿using System;
using System.Xml;

namespace TaskBarLauncher
{
    public static class Extensions
    {
        public static string GetAttribute(this XmlNode node, string key)
        {
            return node.GetAttribute(key, "");
        }

        public static string GetAttribute(this XmlNode node, string key, string defaultValue)
        {
            var value = node.Attributes[key];
            return value == null ? defaultValue : value.Value;
        }

        public static int ToInt(this string value, int defaultValue)
        {
            int res;
            return Int32.TryParse(value, out res) ? res : defaultValue;
        }

        public static XmlNode GetNode(this XmlNodeList list, string elem)
        {
            for (int i = 0; i < list.Count; ++i)
            {
                if (list[i].Name == elem)
                {
                    return list[i];
                }
            }
            return null;
        }
    }
}
